/*带背景的输入布局
* 背景：默认白色
* 背景形状：1.圆角矩形  2.左右圆弧矩形
* 输入类型：1.手机号，2.密码，3.验证码
* 展示样式类型：
* （1）手机号
* 1-1.左侧带图标，1-2.左侧显示"+86"
* */

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:frametrim/utility/sq_color.dart';

class TextFieldPhone extends StatefulWidget {
  //输入类型  例如是左侧带图标的手机号  就传入‘1-1’
  late String inputType;

  //左侧图标  传入Image,如果不显示就传入一个Container()
  late Widget imageLeft;
  TextEditingController _controller = TextEditingController();

  //hite文本
  late String hiteText;

  TextFieldPhone(
      this.inputType, this.imageLeft, this.hiteText, this._controller);

  @override
  State<StatefulWidget> createState() => TextFieldPhoneState();
}

class TextFieldPhoneState extends State<TextFieldPhone> {
  @override
  Widget build(BuildContext context) {
    return Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.center,
        children: buildTextFiled());
  }

  List<Widget> buildTextFiled() {
    List<Widget> children = [];
    children.add(widget.inputType == '1-1'
        ? widget.imageLeft
        : Row(
            children: <Widget>[
              SizedBox(width: 10),
              Text(
                '+86',
                style: TextStyle(
                    fontSize: 14,
                    color: SQColor.color_222222,
                    fontWeight: FontWeight.bold),
              ),
              SizedBox(width: 10)
            ],
          ));
    children.add(Expanded(
      child: TextField(
        maxLength: 11,
        //键盘样式
        keyboardType: TextInputType.number,
        controller: widget._controller,
        decoration: InputDecoration(
          // 去除输入框底部的字符计数,例如11/20
          counterText: '',

          /*去掉下划线*/
          // border: InputBorder.none,

          //contentPadding+border 设置TextField垂直居中
          contentPadding: EdgeInsets.symmetric(vertical: 0),
          border: OutlineInputBorder(borderSide: BorderSide.none),

          hintText: widget.hiteText,
          hintStyle: TextStyle(fontSize: 15, color: SQColor.color_aeaeae),
          labelStyle: TextStyle(fontSize: 15, color: SQColor.black),
        ),
      ),
    ));
    return children;
  }
}
